package com.dk.service.impl;

import com.dk.data.PageBean;
import com.dk.entity.TCar;
import com.dk.mapper.TCarMapper;
import com.dk.service.ITCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2021-11-01
 */
@Service
public class TCarServiceImpl extends ServiceImpl<TCarMapper, TCar> implements ITCarService {

    @Autowired
    private TCarMapper carMapper;

    @Override
    public PageBean findAllByPriceAsc(Integer num, Integer size) {
        PageBean page = new PageBean();
        page.setPageNumber(num);
        page.setPageSize(size);
        List<TCar> carList = carMapper.findAllByPriceAsc(page.getStartIndex(),page.getPageSize());
        page.setList(carList);
        Integer count=carMapper.getTotalCount();
        page.setTotalCount(count);
        return page;
    }

    @Override
    public PageBean findAllByPriceDesc(Integer num, Integer size) {
        PageBean page=new PageBean();
        page.setPageNumber(num);
        page.setPageSize(size);
        List<TCar> carList= carMapper.findAllByPriceDesc(page.getStartIndex(),page.getPageSize());
        page.setList(carList);
        Integer count=carMapper.getTotalCount();
        page.setTotalCount(count);
        return page;
    }

    @Override
    public PageBean findAllByAgeDesc(Integer num, Integer size) {
        PageBean page=new PageBean();
        page.setPageNumber(num);
        page.setPageSize(size);
        List<TCar> carList= carMapper.findAllByAgeDesc(page.getStartIndex(),page.getPageSize());
        page.setList(carList);
        Integer count=carMapper.getTotalCount();
        page.setTotalCount(count);
        return page;
    }

    @Override
    public PageBean findAllByMileageAsc(Integer num, Integer size) {
        PageBean page=new PageBean();
        page.setPageNumber(num);
        page.setPageSize(size);
        List<TCar> carList= carMapper.findAllByMileageAsc(page.getStartIndex(),page.getPageSize());
        page.setList(carList);
        Integer count=carMapper.getTotalCount();
        page.setTotalCount(count);
        return page;
    }
}
